package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
)

func main()  {
	params:= map[string]string{
		 "q": "", "page": "1", "page_size": "100",
	}
	Get( "https://hub.docker.com/api/content/v1/products/search",params)
	//Get("https://hub.docker.com/api/content/v2",nil)
}

func Get(path string, paras map[string]string)  {
	params := url.Values{}
	Url, err := url.Parse(path)
	if err != nil {
		return
	}
	for k, para := range paras {
		params.Set(k,para)
		fmt.Printf("%v:%v\n",k,para)
	}
	//如果参数中有中文参数,这个方法会进行URLEncode
	Url.RawQuery = params.Encode()
	urlPath := Url.String()
	fmt.Println(urlPath) // https://httpbin.org/get?age=23&name=zhaofan
	resp,err := http.Get(urlPath)
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println( string(body))
}
